package com.young.core.dao.impl;


import com.young.core.dao.BaseDao;
import com.young.core.dao.BrokerDao;
import com.young.core.domain.BrokerDO;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class BrokerDaoImpl extends BaseDao implements BrokerDao {


    @Override
    public void insert(BrokerDO broker) {
        this.sqlSession.insert("BrokerMapper.insert", broker);
    }

    @Override
    public boolean keepAlive(String ip) {
        int rn = this.sqlSession.update("BrokerMapper.keepAlive", ip);
        return rn > 0;
    }

    @Override
    public BrokerDO get(String ip) {
        return this.sqlSession.selectOne("BrokerMapper.getByIp", ip);
    }

    @Override
    public List<BrokerDO> getAll() {
        return this.sqlSession.selectList("BrokerMapper.getAll");
    }

    @Override
    public void delete(String ip) {
        this.sqlSession.delete("BrokerMapper.deleteByIp", ip);
    }

    @Override
    public int expire(int ttl) {
        return this.sqlSession.delete("BrokerMapper.deleteExpired", ttl);
    }
}
